<?php
namespace App\Http\Controllers\Grade;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class GradeController extends Controller{
    public function grade_index(){
        $info=DB::table("grade")->get();
        return view("Grade/index",["info"=>$info]);
    }
    public function  grade_insert(Request $r){
        $data=$r->except('_token');
        if ($r->hasFile('grade_image')) {
            $file = $r->file('grade_image');
            $file->move('uploads/Grade', $file->getClientOriginalName());
            $data['grade_image'] = 'http://huya.hk/uploads/Grade/' . $file->getClientOriginalName();
        }
        if ($r->hasFile('grade_images')) {
            $file = $r->file('grade_images');
            $file->move('uploads/Grade', $file->getClientOriginalName());
            $data['grade_images'] ='http://www.huyaa.com/uploads/Grades/' . $file->getClientOriginalName();
        }
        $data['grade_addtime']=date('Y-m-d H:i:s', time());
        $info=DB::table('grade')->insert($data);
        if($info){
            return redirect('grade_index');
        }
    }
    public function grades_index(){
        $info=DB::table("grades")->get();
        return view("Grade/show",["info"=>$info]);
    }
    public function  grades_insert(Request $r){
        $data=$r->except('_token');
        if ($r->hasFile('grades_image')) {
            $file = $r->file('grades_image');
            $file->move('uploads/Grades', $file->getClientOriginalName());
            $data['grades_image'] = 'http://www.huyaa.com/uploads/Grades/' . $file->getClientOriginalName();
        }
        if ($r->hasFile('grades_images')) {
            $file = $r->file('grades_images');
            $file->move('uploads/Grades', $file->getClientOriginalName());
            $data['grades_images'] = 'http://www.huyaa.com/uploads/Grades/' . $file->getClientOriginalName();
        }
        $data['grades_addtime']=date('Y-m-d H:i:s', time());
        $info=DB::table('grades')->insert($data);
        if($info){
            return redirect('grades_index');
        }
    }
    public function grade_delete($id){
        $info=DB::table("grade")->where("id",$id)->delete();
        if($info){
            return redirect("grade_index");
        }else{
            echo "删除失败";
        }
    }
    public function grades_delete($id){
        $info=DB::table("grades")->where("id",$id)->delete();
        if($info){
            return redirect("grades_index");
        }else{
            echo "删除失败";
        }
    }
}